package com.qf.java2107.yb.hotel.controller.foodtype_bak;

import com.qf.java2107.yb.hotel.common.ResultVO;
import com.qf.java2107.yb.hotel.entity.BeanFactory;
import com.qf.java2107.yb.hotel.service.FoodTypeService;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

/**
 * @author yb
 * @version 1.0
 * @date 2021-10-28
 **/
//@WebServlet("/foodtype/list")
public class FoodTypeListController extends HttpServlet {

    private FoodTypeService foodTypeService = (FoodTypeService) BeanFactory.getBean("foodTypeService");

    @Override
    public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        //response.setContentType("text/html;charset=UTF-8");

        PrintWriter out = response.getWriter();

        ResultVO vo = foodTypeService.findAll();

        if(vo.getSuccess()) {
            //String json = JSON.toJSONString(vo.getData());
            //out.write(json);

            request.setAttribute("types", vo.getData());
            request.getRequestDispatcher(request.getContextPath() + "/backend/detail/foodtype/foodtype-list.jsp").forward(request, response);

        } else {
            out.write((String) vo.getData());

        }

    }

    @Override
    public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doGet(request, response);
    }

}
